import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
class NetworkPdfViewerPage extends StatefulWidget {
  var url;

  NetworkPdfViewerPage({this.url});

  @override
  _NetworkPdfViewerPageState createState() => _NetworkPdfViewerPageState();
}

class _NetworkPdfViewerPageState extends State<NetworkPdfViewerPage> {
  final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey();
  final PdfViewerController _controller = PdfViewerController();

   String pdfUrl =
      'https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf';
  String pdfUrl2='https://jynlz-test.oss-cn-beijing.aliyuncs.com/test/pdf/test-pdf.pdf';//'https://jynlz-test.oss-cn-beijing.aliyuncs.com/test/pdf/test-pdf.pdf';
   @override
  void initState() {
    // TODO: implement initState
    super.initState();
    pdfUrl=widget.url;
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('网络 PDF 查看'),
        actions: <Widget>[
          IconButton(
            icon: const Icon(Icons.arrow_drop_down_circle),
            tooltip: '跳转第 3 页',
            onPressed: () {
              _controller.jumpToPage(3);
            },
          ),
          IconButton(
            icon: const Icon(Icons.search),
            tooltip: '搜索 Flutter',
            onPressed: () {
              // _pdfViewerKey.currentState?.searchText('Flutter');
            },
          ),
          IconButton(
            icon: const Icon(Icons.zoom_in),
            tooltip: '放大',
            onPressed: () {
              _controller.zoomLevel = _controller.zoomLevel + 0.25;
            },
          ),
          IconButton(
            icon: const Icon(Icons.zoom_out),
            tooltip: '缩小',
            onPressed: () {
              _controller.zoomLevel = _controller.zoomLevel - 0.25;
            },
          ),
        ],
      ),
      body: SfPdfViewer.network(
        pdfUrl,
        key: _pdfViewerKey,
        controller: _controller,
        canShowScrollHead: true,
        canShowScrollStatus: true,
        enableDoubleTapZooming: true,
        onDocumentLoaded: (details) {
          print('PDF 加载完成，总页数: ${details.document.pages.count}');
        },
        onDocumentLoadFailed: (details) {
          print('加载失败: ${details.error}');
        },
      ),
    );
  }
}
